package com.cm.caseManagement.controller;


import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmGeneralCodeTable;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmGeneralCodeTableService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 通用码Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/table")
public class CmGeneralCodeTableController extends BaseController
{
    @Autowired
    private ICmGeneralCodeTableService cmGeneralCodeTableService;

    /**
     * 查询通用码列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmGeneralCodeTable cmGeneralCodeTable)
    {
        startPage();
        List<CmGeneralCodeTable> list = cmGeneralCodeTableService.selectCmGeneralCodeTableList(cmGeneralCodeTable);
        return getDataTable(list);
    }

    /**
     * 导出通用码列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:table:export')")
    @Log(title = "通用码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmGeneralCodeTable cmGeneralCodeTable)
    {
        List<CmGeneralCodeTable> list = cmGeneralCodeTableService.selectCmGeneralCodeTableList(cmGeneralCodeTable);
        ExcelUtil<CmGeneralCodeTable> util = new ExcelUtil<CmGeneralCodeTable>(CmGeneralCodeTable.class);
        util.exportExcel(response, list, "通用码数据");
    }

    /**
     * 获取通用码详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:table:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmGeneralCodeTableService.selectCmGeneralCodeTableById(id));
    }

    /**
     * 新增通用码
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:table:add')")
    @Log(title = "通用码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmGeneralCodeTable cmGeneralCodeTable)
    {
        return toAjax(cmGeneralCodeTableService.insertCmGeneralCodeTable(cmGeneralCodeTable));
    }

    /**
     * 修改通用码
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:table:edit')")
    @Log(title = "通用码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmGeneralCodeTable cmGeneralCodeTable)
    {
        return toAjax(cmGeneralCodeTableService.updateCmGeneralCodeTable(cmGeneralCodeTable));
    }

    /**
     * 删除通用码
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:table:remove')")
    @Log(title = "通用码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmGeneralCodeTableService.deleteCmGeneralCodeTableByIds(ids));
    }
}
